<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="医生姓名" prop="doctorName">
        <el-input
          v-model="queryParams.doctorName"
          placeholder="请输入医生姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:doctor:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:doctor:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:doctor:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:doctor:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="doctorList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="医生编号" align="center" prop="did" />
      <el-table-column label="医生姓名" align="center" prop="doctorName" />
      <el-table-column label="医生照片" align="center" prop="doctorImg">
        <template slot-scope="scope">
          <el-avatar shape="square" :size="100" fit="fit" :src="scope.row.doctorImg"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:doctor:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:doctor:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handletext(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            icon="el-icon-user-solid"
            @click="temper(scope.row)"
          >挂号</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改医生信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="医生姓名" prop="doctorName">
          <el-input v-model="form.doctorName" placeholder="请输入医生姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="doctorSex">
          <el-select v-model="form.doctorSex" placeholder="请选择性别">
            <el-option
              v-for="dict in doctorSexOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="doctorAge">
          <el-input v-model="form.doctorAge" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="擅长" prop="doctorGood">
          <el-input v-model="form.doctorGood" placeholder="请输入擅长" />
        </el-form-item>
        <el-form-item label="类型" prop="doctorType">
          <el-select v-model="form.doctorType" placeholder="请选择类型">
            <el-option
              v-for="dict in doctorTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属医院" prop="doctorHospital">
          <el-select v-model="form.doctorHospital" placeholder="请选择所属医院">
            <el-option
              v-for="dict in doctorOptions"
              :key="dict.hid"
              :label="dict.hospitalName"
              :value="dict.hid"
            ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="所属科室" prop="doctorTagId">
          <el-select v-model="form.doctorTagId" placeholder="请选择所属科室">
            <el-option
              v-for="dict in doctorTagIdOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="医生照片">
          <imageUpload v-model="form.doctorImg"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 查看医生信息对话框 -->
    <el-dialog :title="title" :visible.sync="open2" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="医生姓名" prop="doctorName">
          <el-input v-model="form.doctorName" disabled />
        </el-form-item>
        <el-form-item label="性别" prop="doctorSex">
          <el-select v-model="form.doctorSex" disabled>
            <el-option
              v-for="dict in doctorSexOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="doctorAge">
          <el-input v-model="form.doctorAge" disabled />
        </el-form-item>
        <el-form-item label="擅长" prop="doctorGood">
          <el-input v-model="form.doctorGood" disabled />
        </el-form-item>
        <el-form-item label="类型" prop="doctorType">
          <el-select v-model="form.doctorType" disabled>
            <el-option
              v-for="dict in doctorTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属医院" prop="doctorHospitalName">
          <el-select v-model="form.doctorHospitalName" disabled>
            <el-option
              v-for="dict in doctorOptions"
              :key="dict.hid"
              :label="dict.hospitalName"
              :value="dict.hid"
            ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="所属科室" prop="doctorTagId">
          <el-select v-model="form.doctorTagId" disabled>
            <el-option
              v-for="dict in doctorTagIdOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="医生照片">
          <imageUpload v-model="form.doctorImg"/>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--体温分流对话框-->
    <el-dialog :title="title" :visible.sync="open4" width="500px" append-to-body>
      <el-form ref="form" :model="health" :rules="rules" label-width="240px">
        <el-form-item label="今日测量体温">
          <el-input v-model="health.temperature" placeholder="请输入今日测量体温" />
        </el-form-item>
        <el-form-item label="现居住地址">
          <el-input v-model="health.address" placeholder="请输入现居住地址" />
        </el-form-item>
        <el-form-item label="14天内是否接触过发热咳嗽的人员">
            <el-radio-group v-model="health.touch">
              <el-radio label="是" value="true"></el-radio>
              <el-radio label="否" value="false"></el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="是否有发热或咳嗽乏力等症状">
            <el-radio-group v-model="health.fever">
              <el-radio label="是" value="true"></el-radio>
              <el-radio label="否" value="false"></el-radio>
            </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTemper">确 定</el-button>
        <el-button @click="cancel4">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 挂号对话框 -->
<!-- 添加或修改挂号信息对话框 -->
    <el-dialog :title="title" :visible.sync="open3" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="挂号专家" prop="makdDoctorId">
          <el-input v-model="form.makdDoctorId" placeholder="请输入挂号专家" />
        </el-form-item> -->
        <el-form-item label="挂号时间">
          <el-date-picker clearable size="small"
            v-model="form.makeDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择挂号时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="所患疾病">
          <el-input v-model="form.makeStatus" placeholder="请输入所患疾病" />
        </el-form-item>
        <el-form-item label="你的姓名">
          <el-input v-model="form.makeName" placeholder="请输入你的姓名" />
        </el-form-item>
        <el-form-item label="联系方式">
          <el-input v-model="form.makePhone" placeholder="请输入联系方式" />
        </el-form-item>
        <!-- <el-form-item label="所属用户" prop="makeUser">
          <el-input v-model="form.makeUser" placeholder="请输入所属用户" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForms">确 定</el-button>
        <el-button @click="cancel3">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDoctor, getDoctor, delDoctor, addDoctor, updateDoctor, exportDoctor } from "@/api/system/doctor";
import ImageUpload from '@/components/ImageUpload';
import { listHospital, getHospital, delHospital, addHospital, updateHospital, exportHospital } from "@/api/system/hospital";
import { listMake, getMake, delMake, addMake, updateMake, exportMake } from "@/api/system/make";
import { getUserProfile,getUser } from "@/api/system/user";

export default {
  name: "Doctor",
  components: {
    ImageUpload,
  },
  data() {
    return {
      //保存登录用户信息
      user: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 医生信息表格数据
      doctorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open2: false,
      open3: false,
      open4: false,
      // 体温分流所需信息
      message: "",
      health: {
      temperature: 36,
      touch: false,
      fever: false,
      address: null,
      },
      // 性别字典
      doctorSexOptions: [],
      // 类型字典
      doctorTypeOptions: [],
      // 所属科室字典
      doctorTagIdOptions: [],
      // 所属医院字典
      doctorOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        doctorName: null,
      },
      // 医院查询参数
      queryParams2: {
        pageNum: 1,
        pageSize: 10,
        hospitalName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getUser();
    this.getList();
    this.getDicts("sys_user_sex").then(response => {
      this.doctorSexOptions = response.data;
    });
    this.getDicts("a_doctor_type").then(response => {
      this.doctorTypeOptions = response.data;
    });
    this.getDicts("a_doctor_tag").then(response => {
      this.doctorTagIdOptions = response.data;
    });
    listHospital(this.queryParams2).then(response => {
      this.doctorOptions = response.rows;
    });
  },
  methods: {
    //查询当前登录用户信息
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
      });
    },
    /** 查询医生信息列表 */
    getList() {
      this.loading = true;
      listDoctor(this.queryParams).then(response => {
        this.doctorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 性别字典翻译
    doctorSexFormat(row, column) {
      return this.selectDictLabel(this.doctorSexOptions, row.doctorSex);
    },
    // 类型字典翻译
    doctorTypeFormat(row, column) {
      return this.selectDictLabel(this.doctorTypeOptions, row.doctorType);
    },
    // 所属科室字典翻译
    doctorTagIdFormat(row, column) {
      return this.selectDictLabel(this.doctorTagIdOptions, row.doctorTagId);
    },
    // 所属医院字典翻译
    doctorFormat(row, column) {
      getHospital(row.hid).then(response => {
        return response.data.hospitalName;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel3() {
      this.open3 = false;
      this.reset();
    },
    cancel4() {
      this.open4 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        did: null,
        doctorName: null,
        doctorSex: null,
        doctorAge: null,
        doctorGood: null,
        doctorType: null,
        doctorHospital: null,
        doctorTagId: null,
        doctorImg: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.did)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加医生信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const did = row.did || this.ids
      getDoctor(did).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改医生信息";
      });
    },
    /** 查看按钮操作 */
    handletext(row) {
      this.reset();
      const did = row.did || this.ids
      getDoctor(did).then(response => {
        this.form = response.data;
        this.open2 = true;
        this.title = "查看医生信息";
      });
    },
    /**健康申报清空*/
    resetTemper(){
    this.health = {};
    },
    /**体温汇报操作*/
    temper(row){
    this.resetTemper();
    this.title = "健康申报";
    this.open4 = true;
    this.message = row;
    },
    /**体温分流操作*/
    submitTemper(row){
      this.open4 = false;
      if(this.health.temperature <= 35 || this.health.temperature >= 42){
        this.$message.error("体温不正常请重新填写");
        this.open4 = false;
      }else if(this.health.temperature <= 37 && this.health.temperature >= 35 && this.health.touch == "否" && this.health.fever == "否"){
        this.guahao(this.message);
         this.$message({
                   message: '你的体温正常',
                   type: 'success'
                 });
      }else{
        this.guahao2(this.message);
        this.$message({
                  message: '请到发热门诊挂号',
                  type: 'warning'
                });
      }
    },
    /** 发热挂号操作 */
    guahao2(row) {
      this.reset();
      const did = row.did || this.ids
      getDoctor(did).then(response => {
        //this.form = response.data;
        this.form.makdDoctorId="发热门诊医生";
        this.form.makeUser=this.user.userId;
        this.open3 = true;
        this.title = "发热门诊挂号";
      });
    },
    /** 正常挂号操作 */
    guahao(row) {
      this.reset();
      const did = row.did || this.ids
      getDoctor(did).then(response => {
        //this.form = response.data;
        this.form.makdDoctorId=response.data.doctorName;
        this.form.makeUser=this.user.userId;
        this.open3 = true;
        this.title = "挂号";
      });
    },
    /** 挂号提交按钮 */
    submitForms() {
      this.$refs["form"].validate(valid => {
        if (valid) {
            addMake(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open3 = false;
              this.getList();
            });
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.did != null) {
            updateDoctor(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDoctor(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const dids = row.did || this.ids;
      this.$confirm('是否确认删除医生信息编号为"' + dids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDoctor(dids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有医生信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDoctor(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
